import 'package:hive/hive.dart';
part 'TranslateModel.g.dart';

enum Languages {
  auto('自动'),
  zh('简体中文'),
  en('英文'),
  yue('粤语'),
  kor('韩语'),
  th('泰语'),
  pt('葡萄牙语'),
  el('希腊语'),
  bul('保加利亚语'),
  fin('芬兰语'),
  slo('斯洛文尼亚语'),
  cht('繁体中文'),
  wyw('文言文'),
  fra('法语'),
  ara('阿拉伯语'),
  de('德语'),
  nl('荷兰语'),
  est('爱沙尼亚语'),
  cs('捷克语'),
  swe('瑞典语'),
  vie('越南语'),
  jp('日语'),
  spa('西班牙语'),
  ru('俄语'),
  it('意大利语'),
  pl('波兰语'),
  dan('丹麦语'),
  rom('罗马尼亚语'),
  hu('匈牙利语');

  final String zhName;

  const Languages(this.zhName);
}

Map<String, String> code = {
  '0': '',
  '52001': '请求超时',
  '52002': '系统错误',
  '52003': '未授权用户',
  '54000': '必填参数为空',
  '54001': '签名错误',
  '54003': '访问频率受限',
  '54004': '账户余额不足',
  '54009': '语种检测失败',
  '58000': '客户端IP非法',
  '58002': '服务当前已关闭',
  '-1': '未知错误',
};

@HiveType(typeId: 1)
class TranslateModel {
  @HiveField(0)
  final String? result;
  @HiveField(1)
  final String? from;
  @HiveField(2)
  final String? to;
  @HiveField(3)
  final String? errorCode;
  @HiveField(4)
  final String? errorMsg;
  @HiveField(5)
  String? query;
  @HiveField(6, defaultValue: 1)
  int count;
  @HiveField(7, defaultValue: 0)
  int searchTime;

  TranslateModel({
    this.result,
    this.from,
    this.to,
    this.errorCode,
    this.errorMsg,
    this.query,
    this.count = 1,
    this.searchTime = 0,
  });

  factory TranslateModel.fromMap(Map data) {
    return TranslateModel(
      result: data['trans_result']?[0]?['dst'],
      errorCode: data['error_code'],
      errorMsg: data['error_msg'],
      from: data['from'],
      to: data['to'],
    );
  }

  bool get success => errorCode == null;
}
